package sg.edu.nus.iss.team2s.jass.gui;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
import java.text.SimpleDateFormat;

import sg.edu.nus.iss.team2s.jass.dto.JobAdvert;

/**
*
* @author Aye Thazin Kyaw
* @version 1.1
*
*/
public class JobAdvertSearchItem extends Panel {

	private static final long serialVersionUID = 1L;
	private Label lbl_jobTitle = null;
	private Label lbl_salaryRange = null;
	private Label lbl_jobLocation = null;
	private Label lbl_experience = null;
	private Label lbl_postDate = null;
	private Button cmd_details = null;
	private Panel parent = null;
	private JobAdvert jobAdvert = null;
	private JobAdvertDetailScreen detailScreen = null;
	
	public void disableDetails(){
		cmd_details.setVisible(false);
	}
	
	public String getJobTitle(){
		return lbl_jobTitle.getText();
	}
	public String getSalaryRange(){
		return lbl_salaryRange.getText();
	}
	public String getJobLocation(){
		return lbl_jobLocation.getText();
	}
	public String getExperience(){
		return lbl_experience.getText();
	}
	public String getPostDate(){
		return lbl_postDate.getText();
	}
	
//	public void setJobTitle(String jobTitle){
//		lbl_jobTitle.setText(jobTitle);
//	}
//	public void setSalaryRange(String salaryRange){
//		lbl_salaryRange.setText(salaryRange);
//	}
//	public void setJobLocation(String jobLocation){
//		lbl_jobLocation.setText(jobLocation);
//	}
//	public void setExperience(String experience){
//		lbl_experience.setText(experience);
//	}
//	public void setPostDate(String postDate){
//		lbl_postDate.setText(postDate);
//	}
	public void setJobAdvert(JobAdvert jobAdvert)
	{
		this.jobAdvert = jobAdvert;
	}
	public JobAdvert getJobAdvert(){
		return jobAdvert;
	}
//	private JobAdvert jobAdvert = null;
	/**
	 * This is the default constructor
	 */
	
	public JobAdvertSearchItem(Panel parent, JobAdvert jobAdvert) {
		super();
		this.parent = parent;
		this.jobAdvert = jobAdvert;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints06 = new GridBagConstraints();
		gridBagConstraints06.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints06.gridx = 6;
//		gridBagConstraints06.gridwidth = 1;
//		gridBagConstraints06.weightx = 1;
		gridBagConstraints06.gridy = 0;
		
		GridBagConstraints gridBagConstraints05 = new GridBagConstraints();
		gridBagConstraints05.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints05.gridx = 5;
//		gridBagConstraints05.gridwidth = 1;
//		gridBagConstraints05.weightx = 1;
		gridBagConstraints05.gridy = 0;
		
		GridBagConstraints gridBagConstraints04 = new GridBagConstraints();
		gridBagConstraints04.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints04.gridx = 4;
//		gridBagConstraints04.gridwidth = 1;
//		gridBagConstraints04.weightx = 1;
		gridBagConstraints04.gridy = 0;
		
		GridBagConstraints gridBagConstraints03 = new GridBagConstraints();
		gridBagConstraints03.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints03.gridy = 0;
//		gridBagConstraints03.gridwidth = 1;
		gridBagConstraints03.gridx = 3;
		
		GridBagConstraints gridBagConstraints02 = new GridBagConstraints();
		gridBagConstraints02.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints02.gridy = 0;
//		gridBagConstraints02.gridwidth = 1;
		gridBagConstraints02.gridx = 2;
		
		GridBagConstraints gridBagConstraints01 = new GridBagConstraints();
		gridBagConstraints01.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints01.gridy = 0;
//		gridBagConstraints01.gridwidth = 1;
		gridBagConstraints01.gridx = 1;
		
		GridBagConstraints gridBagConstraints00 = new GridBagConstraints();
		gridBagConstraints00.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints00.gridy = 0;
//		gridBagConstraints00.gridwidth = 1;
		gridBagConstraints00.gridx = 0;
		
		this.setSize(300, 200);
		this.setLayout(new GridBagLayout());
		this.add(getLbl_jobTitle(), gridBagConstraints00);
		this.add(getLbl_salaryRange(), gridBagConstraints01);
		this.add(getLbl_jobLocation(), gridBagConstraints02);
		this.add(getLbl_experience(), gridBagConstraints03);
		this.add(getLbl_postDate(), gridBagConstraints05);
		this.add(getCmd_details(), gridBagConstraints06);
	}
	
	/**
	 * This method initializes lbl_jobTitle
	 * 	
	 * @return java.awt.Label	
	 */
	private Label getLbl_jobTitle() {
		if (lbl_jobTitle == null) {
			lbl_jobTitle = new Label(getJobAdvert().getJobTitle());
			lbl_jobTitle.setPreferredSize(new Dimension(150,20));
			
		}
		return lbl_jobTitle;
	}
	/**
	 * This method initializes lbl_salaryRange
	 * 	
	 * @return java.awt.Label	
	 */
	private Label getLbl_salaryRange() {
		if (lbl_salaryRange == null) {
			lbl_salaryRange = new Label(getJobAdvert().getSalaryRange());
			lbl_salaryRange.setPreferredSize(new Dimension(150,20));
			
		}
		return lbl_salaryRange;
	}
	
	/**
	 * This method initializes lbl_jobLocation
	 * 	
	 * @return java.awt.Label	
	 */
	private Label getLbl_jobLocation() {
		if (lbl_jobLocation == null) {
			lbl_jobLocation = new Label(getJobAdvert().getLocation());
			lbl_jobLocation.setPreferredSize(new Dimension(150,20));
			
		}
		return lbl_jobLocation;
	}
	
	/**
	 * This method initializes lbl_experience
	 * 	
	 * @return java.awt.Label	
	 */
	private Label getLbl_experience() {
		if (lbl_experience == null) {
			lbl_experience = new Label(getJobAdvert().getExperience());
			lbl_experience.setPreferredSize(new Dimension(250,20));
			
		}
		return lbl_experience;
	}
	
	/**
	 * This method initializes lbl_postDate
	 * 	
	 * @return java.awt.Label	
	 */
	private Label getLbl_postDate() {
		if (lbl_postDate == null) {
			SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat("dd-MMM-yyyy");
			lbl_postDate = new Label(dateFormatter.format(getJobAdvert().getPostDate()));
			lbl_postDate.setPreferredSize(new Dimension(150,20));
			
		}
		return lbl_postDate;
	}
	
	/**
	 * This method initializes cmd_details
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getCmd_details() {
		if (cmd_details == null) {
			cmd_details = new Button("Details");
			cmd_details.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//parent.remove(JobAdvertSearchItem.this);
					//parent.validate();
					if(detailScreen == null || detailScreen.isVisible() == false){
						detailScreen = new JobAdvertDetailScreen(jobAdvert.getJobAdvertId());
					}
					detailScreen.setVisible(true);
					
				}
			});
			cmd_details.setPreferredSize(new Dimension(150,20));
		}
		return cmd_details;
	}

}
